import userApi from "@/api/acl/user";
const state = {
  userList: [],
};
const mutations = {
  GETUSERS(state, data) {
    state.userList = data;
  },
};
const actions = {
  //获取用户
  async getUsers({ state, commit, getters, dispatch }, data) {
    const { page, limit, searchObj } = data;
    try {
        const result = await userApi.getPageList(page, limit, searchObj);
    if (result.code == 20000) {
      commit("GETUSERS", result.data);
      return "ok";
    } else {
      return Promise.reject(new Error(result.message));
    }
    } catch (error) {
     alert('获取数据失败')   
    }
  },
  //添加或新增用户请求
  async addOrUpdateUser({ state, commit, getters, dispatch }, data) {
    if (!data.id) {
      let result = await userApi.add(data);
    } else {
      let result1 = await userApi.update(data);
    }
  },
};
const getters = {
  items() {
    return (state.userList || {}).items || [];
  },
  total() {
    return state.userList.total;
  },
};

export default {
  state,
  mutations,
  actions,
  getters,
};
